home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / t_os / mu_tool / bascomp.awk next >
Text File  |  1993-11-30  |  996b  |  34 lines

  1. # BASIC Program Optimizer
  2. # delete spaces
  3. # delete comments
  4. #
  5. #   outf            output file name (given by batch file)
  6. #   ix              index for space scanning
  7.  
  8. {
  9.     if (match($0,/^([^"]*"[^"]*")*[^"^']*'/) == 1)
  10.         $0 = substr($0, 1, RLENGTH-1)   # remove comment
  11.  
  12.     gsub(/ +$/,"")                      # remove spaces at tail
  13.  
  14.     match($0,/ +/)                      # remove spaces after line number
  15.     ix = RSTART+1
  16.     $0 = substr($0,1,RSTART) substr($0,RSTART+RLENGTH)
  17.     while (match(substr($0,ix),/^([^"^ ]*"[^"]*")*[^"^ ]* /) != 0){
  18.         ix = ix + RLENGTH-2
  19.         if (match(substr($0,ix),/^[A-Z0-9] +[A-Z0-9]/)){
  20.             $0 = substr($0,1,ix) substr($0,ix-2+RLENGTH)
  21.             ix += 2
  22.         }
  23.         else{
  24.             match(substr($0,ix),/^. +[^ ]/)
  25.             $0 = substr($0,1,ix) substr($0,ix-1+RLENGTH)
  26.             ix ++
  27.         }
  28.     }
  29. }
  30. NF > 1 {
  31. #    print $0
  32.     print $0 > outf                           # output line
  33. }
  34.